package com.binguo.api.response.base;

import java.io.Serializable;
import java.util.List;

public class ActionResponse implements Serializable{
	private static final long serialVersionUID = 1L;

	private List<?> rows;

	private Object data;

	private int page = 1;
	private int pageSize = 10;
	private int total;

	private boolean success;
	private String errorMsg;


	public ActionResponse() {

	}

	public ActionResponse(boolean success) {
		this.success = success;
	}


	public ActionResponse(boolean success, Object data) {
		this.success = success;
		this.data = data;
	}
	public ActionResponse(boolean success, String errorMsg) {
		this.success = success;
		this.errorMsg = errorMsg;
	}

	public static ActionResponse success() {
		ActionResponse ret = new ActionResponse(true);
		return ret;
	}

	public static ActionResponse success(int total) {
		ActionResponse ret = new ActionResponse(true);
		ret.total = total;
		return ret;
	}

	public static ActionResponse success(Object data) {
		ActionResponse ret = new ActionResponse(true,data);
		ret.success = true;
		return ret;
	}

	public static ActionResponse error(String errorMsg) {
		return new ActionResponse(false, errorMsg);
	}

	public static ActionResponse errorf(String errorMsg,Object... args) {
		return error(String.format(errorMsg,args));
	}

	public static ActionResponse error(int code, String errorMsg) {
		ActionResponse ret = new ActionResponse(false, errorMsg);
		return ret;
	}


	public List<?> getRows() {
		return rows;
	}
	public void setRows(List<?> rows) {
		this.rows = rows;
	}
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}
	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getTotal() {
		return total;
	}
	public void setTotal(int total) {
		this.total = total;
	}
	public boolean isSuccess() {
		return success;
	}
	public void setSuccess(boolean success) {
		this.success = success;
	}
	public String getErrorMsg() {
		return errorMsg;
	}
	public void setErrorMsg(String errorMsg) {
		this.errorMsg = errorMsg;
	}

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

	@Override
	public String toString() {
		return "ActionResponse{" +
				"rows=" + rows +
				", data=" + data +
				", page=" + page +
				", pageSize=" + pageSize +
				", total=" + total +
				", success=" + success +
				", errorMsg='" + errorMsg + '\'' +
				'}';
	}
}
